package com.wxh.bomb.netty.thread.queue.bean;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * 网民类，实现Delayed接口
 *
 * @author wxh
 * @date：2017.10.10
 */
public class Netizen implements Delayed {
    // 名称
    private String name;
    // 身份证
    private String id;
    // 交的钱
    private int money;
    // 截止时间
    private long endTime;
    // 时间单位
    private TimeUnit timeUnit = TimeUnit.SECONDS;

    public Netizen(String name, String id, int money) {
        this.name = name;
        this.id = id;
        this.money = money;
        this.endTime = 1000 * money + System.currentTimeMillis();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }

    public long getEndTime() {
        return endTime;
    }

    public void setEndTime(long endTime) {
        this.endTime = endTime;
    }

    /**
     * 用来判断是否到了截止时间
     */
    @Override
    public long getDelay(TimeUnit unit) {
        return endTime - System.currentTimeMillis();
    }

    /**
     * 相互批较排序用
     */
    @Override
    public int compareTo(Delayed delayed) {
        Netizen w = (Netizen) delayed;
        return this.getDelay(this.timeUnit) - w.getDelay(this.timeUnit) > 0 ? 1 : 0;
    }
}
